package com.bookShop.action;

import java.util.ArrayList;
import java.util.List;

import com.bookShop.dao.BigTypeDao;
import com.bookShop.dao.BookDao;
import com.bookShop.dao.SmallTypeDao;
import com.bookShop.dao.impl.BigTypeDaoImpl;
import com.bookShop.dao.impl.BookDaoImpl;
import com.bookShop.dao.impl.SmallTypeDaoImpl;
import com.bookShop.entity.BigType;
import com.bookShop.entity.Book;
import com.bookShop.entity.SmallType;
import com.bookShop.tool.MyConstants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class IndexAction extends ActionSupport {

	private Book book;
	private BigType bigType;
	private SmallType smallTyep;
	private BookDao bd;
	private BigTypeDao btd;
	private SmallTypeDao std;

	public IndexAction() {
		bd = new BookDaoImpl();
		btd = new BigTypeDaoImpl();
		std = new SmallTypeDaoImpl();
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}
	
	
	public BigType getBigType() {
		return bigType;
	}

	public void setBigType(BigType bigType) {
		this.bigType = bigType;
	}

	public SmallType getSmallTyep() {
		return smallTyep;
	}

	public void setSmallTyep(SmallType smallTyep) {
		this.smallTyep = smallTyep;
	}

	public String execute() throws Exception {

		List<Book> freeBooks = new ArrayList<Book>();
		List<Book> newBooks = new ArrayList<Book>();

		freeBooks = bd.selectBooks(3, 1,0, MyConstants.FREEBOOKS);
		newBooks = bd.selectBooks(3, 1,0, MyConstants.NEWBOOKS);

		ActionContext.getContext().getSession().put("FB", freeBooks);
		ActionContext.getContext().getSession().put("NB", newBooks);
		
		return SUCCESS;
	}
	
	public String showLeft() throws Exception{
		
		List<BigType> bigTypes = new ArrayList<BigType>();
		List<SmallType> smallTypes = new ArrayList<SmallType>();
		
		bigTypes = btd.selectAll();
		smallTypes = std.selectAll();
		
		ActionContext.getContext().getSession().put("BTS", bigTypes);
		ActionContext.getContext().getSession().put("STS", smallTypes);
		
		return SUCCESS;
	}

}
